
* Higashijima, Masaaki. "Blatant Electoral Frand and the Value of a Vote" (Japanese Journal of Political Science)


**** code variables ****
drop both_fraud
generate both_fraud = .
replace both_fraud = 3 if election_violence == 1 & electoral_fraud ==1 
replace both_fraud = 2 if election_violence == 0 & electoral_fraud ==1
replace both_fraud = 1 if election_violence == 1 & electoral_fraud ==0
replace both_fraud = 0 if election_violence == 0 & electoral_fraud ==0
summarize both_fraud election_violence electoral_fraud 

drop both_fraud2
generate both_fraud2 = .
replace both_fraud2 = 1 if election_violence == 1 & electoral_fraud ==1 
replace both_fraud2 = 0 if election_violence == 0 & electoral_fraud ==1
replace both_fraud2 = 0 if election_violence == 1 & electoral_fraud ==0
replace both_fraud2 = 0 if election_violence == 0 & electoral_fraud ==0
summarize both_fraud2 election_violence electoral_fraud

* add victory uncertainty * constraints
drop uncertain_const
generate uncertain_const = victoryuncertain*xconst

* violence or fraud 

drop only_violence
generate only_violence =. 
replace only_violence = 1 if election_violence==1 & electoral_fraud ==0
replace only_violence = 0 if election_violence==0 & electoral_fraud ==0
replace only_violence = 0 if election_violence==1 & electoral_fraud ==1
replace only_violence = 0 if election_violence==0 & electoral_fraud ==1
summarize only_violence

drop only_cheating
generate only_cheating =. 
replace only_cheating = 1 if election_violence==0 & electoral_fraud ==1
replace only_cheating = 0 if election_violence==0 & electoral_fraud ==0
replace only_cheating = 0 if election_violence==1 & electoral_fraud ==1
replace only_cheating = 0 if election_violence==1 & electoral_fraud ==0
summarize only_cheating

* Table 1

* Model 1
#delimit 
xtlogit only_violence mal1 victoryuncertain xconst uncertain_const
pii_ma3 recruit_3ma polcom_3ma lag_loggdppc lag_log_pop lag_civilwar 
demonstration leadertenure leaderage yy3 yy4 yy5 yy6 yy7 yy8 yy11 yy14 yy15, vce(robust);

#delimit cr;
* compute BIC 
estat ic

* Model 2
#delimit 
xtlogit only_cheating mal1 victoryuncertain xconst uncertain_const
pii_ma3 recruit_3ma polcom_3ma lag_loggdppc lag_log_pop 
demonstration leadertenure leaderage yy4 yy9 yy11 yy12 yy13 yy14 yy15 yy18, vce(robust);

#delimit cr;
estat ic

* Model 3
#delimit 
xtlogit both_fraud2 mal1 victoryuncertain xconst uncertain_const
pii_ma3 recruit_3ma polcom_3ma lag_loggdppc lag_log_pop lag_civilwar 
demonstration leadertenure leaderage yy4 yy5 yy7 yy9 yy12-yy18, vce(robust);

#delimit cr;
estat ic

* compute predicted probabilities
margins, at(mal1=(0(0.025)0.3))
marginsplot,  recastci(rconnected) ciopts(lcolor(black)) level(95) addplot(histogram mal1 if e(sample)==1, fcolor(none) lcolor(gs11) yscale(alt) yaxis(2) legend(off))  


* Descriptive statistics (Appendix A2) 
#delimit 
summarize only_violence only_cheating both_fraud2 mal1 victoryuncertain xconst uncertain_const
pii_ma3 recruit_3ma polcom_3ma lag_loggdppc lag_log_pop lag_civilwar 
demonstration leadertenure leaderage if e(sample) ;
#delimit cr; 


* Appendix B1: Alternative estimator: multi nomial probit

* 1
#delimit 
mprobit  both_fraud mal1 victoryuncertain xconst uncertain_const
pii_ma3 recruit_3ma polcom_3ma lag_loggdppc lag_log_pop lag_civilwar 
demonstration leadertenure leaderage, cluster(ccode);

#delimit cr;
estat ic

margins, at(mal1=(0(0.025)0.3)) predict(outcome(3))
marginsplot,  recastci(rconnected) ciopts(lcolor(black)) level(95) addplot(histogram mal1 if e(sample)==1, fcolor(none) lcolor(gs11) yscale(alt) yaxis(2) legend(off))  

* 2
#delimit 
mprobit  both_fraud mal1 victoryuncertain xconst uncertain_const
pii_ma3 recruit_3ma polcom_3ma lag_loggdppc lag_log_pop lag_civilwar 
demonstration leadertenure leaderage, baseoutcome(1) cluster(ccode);

#delimit cr;
estat ic

margins, at(mal1=(0(0.025)0.3)) predict(outcome(3))
marginsplot,  recastci(rconnected) ciopts(lcolor(black)) level(95) addplot(histogram mal1 if e(sample)==1, fcolor(none) lcolor(gs11) yscale(alt) yaxis(2) legend(off))  

* 3 
#delimit 
mprobit both_fraud mal1 victoryuncertain xconst uncertain_const
pii_ma3 recruit_3ma polcom_3ma lag_loggdppc lag_log_pop
demonstration leadertenure leaderage, baseoutcome(2) cluster(ccode);

#delimit cr;
estat ic

margins, at(mal1=(0(0.025)0.3)) predict(outcome(3))
marginsplot,  recastci(rconnected) ciopts(lcolor(black)) level(95) addplot(histogram mal1 if e(sample)==1, fcolor(none) lcolor(gs11) yscale(alt) yaxis(2) legend(off))  



* Table B2: Additional controls

#delimit 
xtlogit both_fraud2 mal1 victoryuncertain xconst uncertain_const
pii_ma3 recruit_3ma polcom_3ma lag_loggdppc lag_log_pop lag_civilwar 
demonstration leadertenure leaderage eet expenditure yy4 yy5 yy7 yy9 yy12-yy18, vce(robust);

#delimit cr;
estat ic

margins, at(mal1=(0(0.025)0.3))
marginsplot,  recastci(rconnected) ciopts(lcolor(black)) level(95) addplot(histogram mal1 if e(sample)==1, fcolor(none) lcolor(gs11) yscale(alt) yaxis(2) legend(off))  

* Table B3: Alternative measurement

* code variables
summarize violence_vdem cheating_vdem 
drop both_fraud_vdem
generate both_fraud_vdem = .
replace both_fraud_vdem = 0 if violence_vdem >=1.15 & cheating_vdem > 0.634 
replace both_fraud_vdem = 0 if violence_vdem < 1.15 & cheating_vdem > 0.634
replace both_fraud_vdem = 0 if violence_vdem >= 1.15 & cheating_vdem <= 0.634
replace both_fraud_vdem = 1 if violence_vdem < 1.15 & cheating_vdem <= 0.634
 
#delimit 
xtlogit both_fraud_vdem mal1 victoryuncertain xconst uncertain_const
pii_ma3 recruit_3ma polcom_3ma lag_loggdppc lag_log_pop lag_civilwar 
demonstration leadertenure leaderage if electoral_fraud!=., vce(robust);

#delimit cr;
estat ic

summarize both_fraud_vdem if e(sample)

* Table B4: Developing countries

#delimit 
xtlogit both_fraud2 mal1 victoryuncertain xconst uncertain_const
pii_ma3 recruit_3ma polcom_3ma lag_loggdppc lag_log_pop lag_civilwar 
demonstration leadertenure leaderage yy4 yy5 yy7 yy9 yy12-yy18 if oecd==0, vce(robust);

#delimit cr;
estat ic

margins, at(mal1=(0(0.025)0.3))
marginsplot,  recastci(rconnected) ciopts(lcolor(black)) level(95) addplot(histogram mal1 if e(sample)==1, fcolor(none) lcolor(gs11) yscale(alt) yaxis(2) legend(off))  


* Table B5: Time dependence 

* create time lapse and polynomial variables
drop time_both_fraud2 time_both_fraud22 time_both_fraud23
btscs  both_fraud2 election_year ccode, generate(time_both_fraud2)

generate time_both_fraud22 = time_both_fraud2*time_both_fraud2
generate time_both_fraud23 = time_both_fraud2*time_both_fraud2*time_both_fraud2

#delimit 
xtlogit  both_fraud2 mal1 victoryuncertain xconst uncertain_const
pii_ma3 recruit_3ma polcom_3ma lag_loggdppc lag_log_pop lag_civilwar 
demonstration leadertenure leaderage yy4 yy5 yy7 yy9 yy12-yy18
time_both_fraud2 time_both_fraud22 time_both_fraud23
, vce(robust);

#delimit cr;
estat ic

margins, at(mal1=(0(0.025)0.3))
marginsplot,  recastci(rconnected) ciopts(lcolor(black)) level(95) addplot(histogram mal1 if e(sample)==1, fcolor(none) lcolor(gs11) yscale(alt) yaxis(2) legend(off))  

* Table B6: Jackknife analaysis

* make country identifier
drop country_id 
egen country_id = group(ccode) if e(sample)
summarize country_id
drop year_id 
egen year_id = group(election_year) if e(sample)
summarize year_id

** (i) country

** Model 1
set scrollbufsize 300000

forval i=1/98 {
xtlogit both_fraud2 mal1 victoryuncertain xconst uncertain_const pii_ma3 recruit_3ma polcom_3ma lag_loggdppc lag_log_pop lag_civilwar demonstration leadertenure leaderage if country_id!=`i'
estimates store m`i', title(Model`i') 
} 

* make coefficient plots

coefplot m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 m13 m14 m15 m16 m17 m18 m19 m20, xline(0) keep(mal1) levels(95, 90)
coefplot m21 m22 m23 m24 m25 m26 m27 m28 m29 m30 m31 m32 m33 m34 m35 m36 m37 m38 m39 m40, xline(0) keep(mal1) levels(95, 90)
coefplot m41 m42 m43 m44 m45 m46 m47 m48 m49 m50 m51 m52 m53 m54 m55 m56 m57 m58 m59 m60, xline(0) keep(mal1) levels(95, 90)
coefplot m61 m62 m63 m64 m65 m66 m67 m68 m69 m70 m71 m72 m73 m74 m75 m76 m77 m78 m79 m80, xline(0) keep(mal1) levels(95, 90)
coefplot m81 m82 m83 m84 m85 m86 m87 m88 m89 m90 m91 m92 m93 m94 m95 m96 m97 m98, xline(0) keep(mal1) levels(95, 90)

** (ii) time period

forval i=1/19 {
xtlogit both_fraud2 mal1 victoryuncertain xconst uncertain_const pii_ma3 recruit_3ma polcom_3ma lag_loggdppc lag_log_pop lag_civilwar demonstration leadertenure leaderage if year_id!=`i'
estimates store m`i', title(Model`i') 
} 

coefplot m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 m13 m14 m15 m16 m17 m18 m19, xline(0) keep(mal1) levels(95, 90)


*** protest (Appendix Table C1) 

* run Model 1 in Table 1 to specify the sample
#delimit 
xtlogit only_violence mal1 victoryuncertain xconst uncertain_const
pii_ma3 recruit_3ma polcom_3ma lag_loggdppc lag_log_pop lag_civilwar 
demonstration leadertenure leaderage yy3 yy4 yy5 yy6 yy7 yy8 yy11 yy14 yy15, vce(robust);

#delimit cr;


* estimate the effect of malapportionment on protests
#delimit
xtlogit nelda29 mal1 pii_ma3 victoryuncertain xconst uncertain_const lag_log_pop lag_loggdppc leadertenure leaderage lag_civilwar
if e(sample), vce(robust) re; 

#delimit cr; 
estat ic

*** Between- and Within-Unit Variances of Electoral Manipulation (Appendix Table C2) 

xtsum election_violence electoral_fraud mal1 if e(sample)



